package com.heima.article.controller;

import com.heima.article.service.ApArticleService;
import com.heima.model.article.dtos.ArticleHomeDto;
import com.heima.model.article.pojos.ApArticle;
import com.heima.model.common.dtos.ResponseResult;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/v1/article")
@AllArgsConstructor
public class ApArticleController {
    private final ApArticleService apArticleService;

    /**
     * 首页信息
     *
     * @param articleHomeDto
     * @return {@link ResponseResult}
     */
    @PostMapping("/load")
    public ResponseResult<List<ApArticle>> load(@RequestBody ArticleHomeDto articleHomeDto){
        List<ApArticle> apArticleList = apArticleService.load(articleHomeDto);
        return ResponseResult.okResult(apArticleList);
    }

    /**
     * 加载更多
     *
     * @param articleHomeDto
     * @return {@link ResponseResult}
     */
    @PostMapping("/loadmore")
    public ResponseResult<List<ApArticle>> loadmore(@RequestBody ArticleHomeDto articleHomeDto){
        List<ApArticle> apArticleList = apArticleService.loadmore(articleHomeDto);
        return ResponseResult.okResult(apArticleList);
    }

    /**
     * 加载新文章
     *
     * @param articleHomeDto
     * @return {@link ResponseResult}
     */
    @PostMapping("/loadnew")
    public ResponseResult<List<ApArticle>> loadnew(@RequestBody ArticleHomeDto articleHomeDto){
        List<ApArticle> apArticleList = apArticleService.loadnew(articleHomeDto);
        return ResponseResult.okResult(apArticleList);
    }
}
